﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

/// <summary>
///ParamHelper 的摘要说明
/// </summary>
public class ParamHelper
{
	public ParamHelper()
	{
	}
    /// <summary>
    /// 转换字符串为正整数，正常大于0，失败返回0
    /// </summary>
    /// <param name="strInt"></param>
    /// <returns></returns>
    public static int ParseIntPositive(string strInt)
    {        
        if (strInt == null || strInt.Length > 10)
        {
            return 0;
        }
        int number = 0;
        int.TryParse(strInt, out number);
       
        return number;
    }
    /// <summary>
    /// 转换字符串为整数，失败返回默认值
    /// </summary>
    /// <param name="strInt"></param>
    /// <returns></returns>
    public static int ParseInt(string strInt, int defaultInt)
    {
        if (strInt == null || strInt.Length > 10)
        {
            return defaultInt;
        }
        int number = defaultInt;        
        int.TryParse(strInt, out number);
       
        return number;
    }
    /// <summary>
    /// 设置下拉列表选中项
    /// </summary>
    /// <param name="ddl"></param>
    /// <param name="selectedValue">选中的值</param>
    public static void SetDropDownListSelectedIndex(DropDownList ddl, string selectedValue)
    {
        int count = ddl.Items.Count;
        for (int i = 0; i < count; i++)
        {
            if (ddl.Items[i].Value == selectedValue)
            {
                ddl.SelectedIndex = i;
                return;
            }
        }
    }
}
